package com.zhj.controller;


import com.zhj.designpatten.OrderServiceImpl;
import com.zhj.po.CmsSubject;
import com.zhj.po.MyUserDetails;
import com.zhj.service.DemoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


/**
 * Copyright: Copyright (c) 2020 hantu
 *
 * @ClassName: DemoController
 * @Description:
 * @version: v1.0.0
 * @author: zhanghaojie
 * @date: 2020/5/6
 */
@RestController
public class DemoController {

    private static Logger LOGGER = LoggerFactory.getLogger(DemoController.class);
    @Autowired
    private DemoService demoService;
    @Autowired
    private OrderServiceImpl orderService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Transactional
    @RequestMapping(value = "/test1",method = RequestMethod.GET)
    public   void test1(){
        CmsSubject cmsSubject = demoService.selectOneById(1);
        System.out.println(cmsSubject);
    }
    @RequestMapping(value = "/testP",method = RequestMethod.GET)
    private  void testP() throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        //orderService.saveOrder();
        Class<?> demoService = Class.forName("DemoService");
        Method method = demoService.getMethod("testZhj",Integer.class);
        method.invoke(demoService,"1");
    }

    /*@RequestMapping(value = "/testRedis",method = RequestMethod.GET)
    private  void testRedis(){

        Object name = redisTemplate.opsForValue().get("testname:zhanghaojie");
        if (name==null){
            MyUserDetails myUserDetails =new MyUserDetails();
            myUserDetails.setUsername("张豪杰");
            myUserDetails.setPassword("123456");
            redisTemplate.opsForValue().set("testname:zhanghaojie",myUserDetails);
            LOGGER.info("当前没有值，设置成功");
        }else {
            LOGGER.info("当前值，值为: "+name);
        }

    }*/

}
